const app = getApp()
import http from '../../utils/http'

Page({
  data: {
        // 下拉选择
        selectWish: ['减脂', '增肌', '均衡营养'],
        selectSport: ['轻量级活动', '中等强度活动', '高强度活动'],
    
        // 个人身体数据
        height: undefined,
        weight: undefined,
        wish: -1,
        sport: -1,
  },

  onShow() {
    // 判断是否登录已成功
    if (app.globalData.sessionId) {
      this.setData({
        roleId: app.globalData.roleId
      })
      if (this.data.roleId != 0) {
        this.getUserInfo();
      }
    } else {
      app.userLoginCallback = () => {
        if (app.globalData.sessionId) {
          this.setData({
            roleId: app.globalData.roleId
          })
          if (this.data.roleId != 0) {
            this.getUserInfo();
          }
        }
      };
    }
  },

  // 获取用户基本信息
  getUserInfo: function () {
    http({
      url: '/user/get',
      success: (result) => {
        console.log(result)
        this.setData({
          height: result.info.height,
          weight: result.info.weight,
          wish: result.info.wish,
          sport: result.info.sport
        })
        console.log(result);
      }
    })
  },

  toUpdateInfo(){
    wx.navigateTo({
      url: '../me_inner/update/update',
    })
  },
  toFeedBack(){
    wx.navigateTo({
      url: '../me_inner/feedback/feedback',
    })
  }
  
})